<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @row-update="rowUpdate"
      @row-save="rowSave"
      @row-del="rowDel"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot="menuLeft">
        <el-button size="mini" type="primary" @click="handleManageValue"
          >管理诚信值</el-button
        >
      </template>
    </avue-crud>
    <!-- 管理诚信值弹窗 -->
    <el-dialog
      :visible.sync="isShowModal"
      append-to-body
      destroy-on-close
      title="管理诚信值"
      width="40%"
    >
      <el-form ref="auditFormRef" :rules="formRules" :model="auditForm">
        <el-form-item label="管理对象：">
          <div>
            <span>陈陈（188 8888 8888）</span> <span>当前诚信值：0.5</span>
          </div>
        </el-form-item>
        <el-form-item label="管理类型：" prop="type">
          <el-radio-group v-model="auditForm.type">
            <el-radio :label="'success'">加分</el-radio>
            <el-radio :label="'fail'">减分</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="分值：" prop="score">
          <el-input-number
            v-model="auditForm.score"
            :min="0"
            :step="1"
            style="width: 100%"
            placeholder="请输入"
          />
        </el-form-item>
        <el-form-item label="操作原因：" prop="reason">
          <el-input
            type="textarea"
            v-model="auditForm.reason"
            placeholder="请输入操作原因"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="submitCancelAudit()"> 取消 </el-button>
        <el-button type="primary" @click="submitAudit()"> 确认 </el-button>
      </div>
    </el-dialog>
  </basic-container>
</template>

<script>
import { mapGetters } from "vuex";

export default {
  data() {
    return {
      form: {},
      query: {},
      loading: false,
      page: {
        currentPage: 1,
        pageSize: 10,
        total: 0,
      },
      selectionList: [],
      option: {
        menu: false,
        menuType: "button",
        height: "auto",
        calcHeight: 30,
        tip: false,
        searchShow: false,
        searchMenuSpan: 6,
        border: false,
        index: false,
        indexLabel: "序号",
        searchBtnText: "提交",
        searchBtnIcon: "提交",
        emptyBtnText: "重置",
        emptyBtnIcon: "重置",
        viewBtn: false,
        addBtn: false,
        addBtnText: "添加",
        addBtnIcon: "el-icon-plus",
        editBtn: false,
        editBtnText: "",
        selection: false,
        dialogClickModal: false,
        delBtn: false,
        delBtnText: "",
        labelWidth: 110,
        searchLabelWidth: 100,
        column: [
          {
            label: "分值",
            prop: "score",
          },
          {
            label: "剩余诚信值",
            prop: "RemainingCreditworthiness",
          },
          {
            label: "操作原因",
            prop: "OperationalReasons",
          },
          {
            label: "操作人",
            prop: "Operator",
          },
          {
            label: "操作时间",
            prop: "OperateTime",
          },
        ],
      },
      data: [
        {
          score: "-0.1",
          RemainingCreditworthiness: "0.9",
          OperationalReasons: "乘客投诉--2025-05-13 19:30 成都-广安",
          Operator: "管理员张三",
          OperateTime: "2025-10-10 12:13:13",
        },
      ],
      currentItemData: null,
      isShowModal: false,
      auditForm: {
        type: "",
        score: "",
        reason: "",
      },
      formRules: {
        // type: [
        //   {
        //     required: true,
        //     message: "请选择审核结果",
        //     trigger: "change",
        //   },
        // ],
        // reason: [
        //   {
        //     required: true,
        //     message: "请输入审核意见",
        //     trigger: "blur",
        //   },
        // ],
      },
    };
  },
  computed: {
    ...mapGetters(["permission"]),

    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.user_add, true),
        viewBtn: this.vaildData(this.permission.user_view, true),
        delBtn: this.vaildData(this.permission.user_delete, true),
        editBtn: this.vaildData(this.permission.user_edit, true),
      };
    },
  },
  mounted() {},
  methods: {
    // 管理诚信值相关
    handleManageValue(data) {
      this.currentItemData = data;
      this.isShowModal = true;
    },
    submitCancelAudit() {
      this.isShowModal = false;
      this.$refs["auditFormRef"].resetFields();
    },
    submitAudit() {
      return;
      this.$refs["auditFormRef"].validate((valid) => {
        if (valid) {
          const tempData = Object.assign(
            { id: this.currentItemData.id },
            this.auditForm
          );
          xxx(tempData).then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!",
            });
            this.isShowModal = false;
            this.auditForm = {};
          });
        }
      });
    },
    beforeOpen(done, type) {
      done();
    },
    onLoad(page, search = {}) {
      return;
      this.loading = true;
      let param = {
        page: page.currentPage,
        size: page.pageSize,
      };

      xxx({ ...param, ...search }).then((res) => {
        const resData = res.data;
        this.page.total = resData.total;
        this.data = resData.list;
        this.loading = false;
        this.selectionClear();
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
